package hydrap2p.test.protocol;

import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.List;

import org.apache.thrift.TException;

import hydrap2p.ServiceLocation;
import hydrap2p.helper.RangeUtils;
import hydrap2p.library.FileAlreadyExists;
import hydrap2p.library.HashData;
import hydrap2p.library.InvalidUID;
import hydrap2p.library.Library;
import hydrap2p.library.LibrarySubscriptionType;
import hydrap2p.library.Range;
import hydrap2p.library.SharedItemInfo;

public class FakeLibrary implements Library.Iface {

	private byte[] data;
	private List<Range> downloadedranges;
	public FakeLibrary(int expectedsize)
	{
		data=new byte[expectedsize];
		downloadedranges=new LinkedList<Range>();
	}


	@Override
	public ByteBuffer loadData(long arg0, long arg1, int arg2) {
		return ByteBuffer.wrap(data, (int)arg1, (int)arg1+arg2);
	}

	@Override
	public boolean saveData(long arg0, long arg1, ByteBuffer arg2) {
		System.arraycopy(arg2, 0, data, (int)arg1, arg2.capacity());
		Range temp=new Range();
		temp.start=arg1;
		temp.len=arg2.capacity();
		downloadedranges=RangeUtils.merge(downloadedranges, temp);
		return true;
	}

	@Override
	public List<Range> getDownloadedRanges(long arg0) {
		return downloadedranges;
	}
	
	@Override
	public long addSharedFolder(String arg0) {
		return 0;
	}

	@Override
	public long createFile(String arg0, long arg1){
		return 0;
	}

	@Override
	public long createFileSet(String arg0, List<Long> arg1){
		return 0;
	}

	@Override
	public void deleteDownloadHash(long arg0, HashData arg1) {	
	}

	@Override
	public boolean deleteExtraData(long arg0, String arg1) {
		return false;
	}

	@Override
	public boolean deleteMetadata(long arg0, String arg1) {
		return false;
	}

	@Override
	public List<SharedItemInfo> getChildren(long arg0) {
		return null;
	}

	@Override
	public SharedItemInfo getSharedItemInfo(long arg0) {
		return null;
	}

	@Override
	public List<Range> getVerifiedRanges(long arg0) throws InvalidUID,
			TException {
		return null;
	}

	@Override
	public boolean registerHashGenerator(String arg0, ServiceLocation arg1)
			{
		return false;
	}

	@Override
	public boolean registerListener(ServiceLocation arg0,
			LibrarySubscriptionType arg1) {
		return false;
	}

	@Override
	public boolean registerMetadataLoader(String arg0, ServiceLocation arg1)
			{
		return false;
	}

	@Override
	public boolean removeSharedFolder(long arg0) throws InvalidUID, TException {
		return false;
	}

	@Override
	public void rescan(long arg0) throws InvalidUID, TException {
	}


	@Override
	public List<SharedItemInfo> searchFilename(String arg0) {
		return null;
	}

	@Override
	public List<SharedItemInfo> searchHash(String arg0, String arg1)
			{
		return null;
	}

	@Override
	public void setDownloadHash(long arg0, HashData arg1) throws InvalidUID,
			TException {
	}

	@Override
	public void setExtraData(long arg0, String arg1, String arg2)
			throws InvalidUID, TException {
	}

	@Override
	public void setFileName(long arg0, String arg1) throws FileAlreadyExists,
			InvalidUID, TException {
	}

	@Override
	public boolean setMetadata(long arg0, String arg1, String arg2)
			throws InvalidUID, TException {
		return false;
	}

	@Override
	public void setPathName(long arg0, String arg1) throws FileAlreadyExists,
			InvalidUID, TException {
	}

	@Override
	public boolean setShared(long arg0, boolean arg1) throws InvalidUID,
			TException {
		return false;
	}

	@Override
	public boolean unregisterHashGenerator(String arg0, ServiceLocation arg1)
			{
		return false;
	}

	@Override
	public boolean unregisterListener(ServiceLocation arg0) {
		return false;
	}

	@Override
	public boolean unregisterMetadataLoader(String arg0, ServiceLocation arg1)
			{
		return false;
	}

	@Override
	public void ping() {
	}

	@Override
	public List<String> supportedInterfaces() {
		return null;
	}

}
